package com.ruoyi.finance.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.finance.domain.AccountSet;
import com.ruoyi.finance.service.IAccountSetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 账套管理Controller
 * 
 * @author 李伟
 * @date 2025-02-24
 */
@RestController
@RequestMapping("/finance/AccountSet")
public class AccountSetController extends BaseController
{
    @Autowired
    private IAccountSetService accountSetService;

    /**
     * 查询账套管理列表
     */
    @PreAuthorize("@ss.hasPermi('finance:AccountSet:list')")
    @GetMapping("/list")
    public TableDataInfo list(AccountSet accountSet)
    {
        startPage();
        List<AccountSet> list = accountSetService.selectAccountSetList(accountSet);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('finance:AccountSet:list')")
    @GetMapping("/listAcountSetAll")
    public AjaxResult listAcountSetAll()
    {
        List<AccountSet> list = accountSetService.selectAccountSetListAllbyUserid();
        return success(list);
    }
    @PreAuthorize("@ss.hasPermi('finance:AccountSet:edit')")
    @PutMapping("/checkDefaultAccountSet/{accountId}")
    public AjaxResult checkDefaultAccountSet(@PathVariable("accountId") Long accountId)
    {
        return toAjax(accountSetService.checkDefaultAccountSet(accountId));
    }
    /**
     * 导出账套管理列表
     */
    @PreAuthorize("@ss.hasPermi('finance:AccountSet:export')")
    @Log(title = "账套管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccountSet accountSet)
    {
        List<AccountSet> list = accountSetService.selectAccountSetList(accountSet);
        ExcelUtil<AccountSet> util = new ExcelUtil<AccountSet>(AccountSet.class);
        util.exportExcel(response, list, "账套管理数据");
    }

    /**
     * 获取账套管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('finance:AccountSet:query')")
    @GetMapping(value = "/{accountId}")
    public AjaxResult getInfo(@PathVariable("accountId") Long accountId)
    {
        return success(accountSetService.selectAccountSetByAccountId(accountId));
    }

    /**
     * 新增账套管理
     */
    @PreAuthorize("@ss.hasPermi('finance:AccountSet:add')")
    @Log(title = "账套管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccountSet accountSet)
    {
        return toAjax(accountSetService.insertAccountSet(accountSet));
    }

    /**
     * 修改账套管理
     */
    @PreAuthorize("@ss.hasPermi('finance:AccountSet:edit')")
    @Log(title = "账套管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccountSet accountSet)
    {
        return toAjax(accountSetService.updateAccountSet(accountSet));
    }

    /**
     * 删除账套管理
     */
    @PreAuthorize("@ss.hasPermi('finance:AccountSet:remove')")
    @Log(title = "账套管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{accountIds}")
    public AjaxResult remove(@PathVariable Long[] accountIds)
    {
        return toAjax(accountSetService.deleteAccountSetByAccountIds(accountIds));
    }


}
